#!/usr/bin/env python
# -*- coding:utf-8 -*-

import sys
from urllib import request, parse
import json

print('登录到认证服务器')

login_data = parse.urlencode([
    ('opr', 'pwdLogin'),
    ('userName', 'yaoyu'),
    ('pwd', '123456'),
    ('rememberPwd', '1'),
])


req = request.Request('http://192.168.1.1/ac_portal/login.php')
req.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:50.0) Gecko/20100101 Firefox/50.0')
req.add_header('Referer', 'http://192.168.1.1/ac_portal/default/pc.html?tabs=pwd')

with request.urlopen(req, data=login_data.encode('utf-8')) as f:
    print('Status:', f.status, f.reason)
    
    #for k, v in f.getheaders():
        #print('%s: %s' % (k, v))
    #if f.status == 200:
        #data = f.read().decode('utf-8').replace("'", '"')
        #data = json.loads(data)
        #print(data)
    